Imports System.Data.SqlClient
Imports System.Data
Partial Class Client_frmDataList
    Inherits System.Web.UI.Page
    Dim _bo As New Bo
    Dim _UserId As String
    Dim dtTable1 As New DataTable
    Dim cntProduct As Integer
    Dim row, i As Integer
    Dim dtTable As New DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            viewstate("min") = 1
            viewstate("max") = 8
            _UserId = Session("UserId")
            dtTable = _bo.extracthomeproduct(viewstate("min"), viewstate("max")) 'getProductDetails()
            DataList.DataSource = dtTable ' c.extracthomeproduct(viewstate("min"), viewstate("max"))
            DataList.DataBind()
        End If
    End Sub

    Protected Sub lnkPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPrevious.Click
        If ddlsort.SelectedItem.ToString = "All" Then
            _bo.extracthomeproduct(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Price" Then
            _bo.getProductByPrice(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Brand" Then
            _bo.getProductByBrand(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Discount" Then
            _bo.getProductByDiscount(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Most Viewed" Then
            _bo.Topbrand(ViewState("min"), ViewState("max")).Rows.Clear()
        End If


        _bo.extracthomeproduct(ViewState("min"), ViewState("max")).Rows.Clear()

        cntProduct = _bo.counttotproduct()
        ViewState("min") = Val(ViewState("min")) - 8
        ViewState("max") = Val(ViewState("max")) - 8


        If ddlsort.SelectedItem.ToString = "All" Then
            DataList.DataSource = _bo.extracthomeproduct(ViewState("min"), ViewState("max"))
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Price" Then
            dtTable = _bo.getProductByPrice(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Brand" Then
            dtTable = _bo.getProductByBrand(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Discount" Then
            dtTable = _bo.getProductByDiscount(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Most Viewed" Then
            dtTable = _bo.Topbrand(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        End If

        'DataList.DataSource = _bo.extracthomeproduct(ViewState("min"), ViewState("max"))
        'DataList.DataBind()

        If ViewState("min") <= 1 Then
            lnkPrevious.Enabled = False
        End If
        If ViewState("max") <= cntProduct Then
            lnkNext.Enabled = True
        End If
    End Sub
    Protected Sub lnkNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkNext.Click
        If ddlsort.SelectedItem.ToString = "All" Then
            _bo.extracthomeproduct(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Price" Then
            _bo.getProductByPrice(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Brand" Then
            _bo.getProductByBrand(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Discount" Then
            _bo.getProductByDiscount(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Most Viewed" Then
            _bo.Topbrand(ViewState("min"), ViewState("max")).Rows.Clear()
        End If

        '_bo.extracthomeproduct(ViewState("min"), ViewState("max")).Rows.Clear()
        cntProduct = _bo.counttotproduct()
        ViewState("min") = Val(ViewState("min")) + 8
        ViewState("max") = Val(ViewState("max")) + 8



        If ddlsort.SelectedItem.ToString = "All" Then
            DataList.DataSource = _bo.extracthomeproduct(ViewState("min"), ViewState("max"))
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Price" Then
            dtTable = _bo.getProductByPrice(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Brand" Then
            dtTable = _bo.getProductByBrand(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Discount" Then
            dtTable = _bo.getProductByDiscount(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Most Viewed" Then
            dtTable = _bo.Topbrand(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        End If
        'DataList.DataSource = _bo.extracthomeproduct(ViewState("min"), ViewState("max"))
        'DataList.DataBind()

        If viewstate("max") > cntProduct Then
            lnkNext.Enabled = False
        End If
        If ViewState("min") > 1 Then
            lnkPrevious.Enabled = True
        End If
    End Sub
    Protected Sub DataList_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList.EditCommand
        If e.CommandName = "Edit" Then
            Dim lnk1 As LinkButton = e.Item.FindControl("Lnk")
            Session("UserId") = _UserId
            Response.Redirect("frmViewProduct.aspx?ProductId=" & lnk1.Text)
        End If
    End Sub
    Protected Sub ddlSort_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlsort.SelectedIndexChanged
        ViewState("min") = 1
        ViewState("max") = 8
        If ddlsort.SelectedItem.ToString = "All" Then
            _bo.extracthomeproduct(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Price" Then
            _bo.getProductByPrice(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Brand" Then
            _bo.getProductByBrand(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Discount" Then
            _bo.getProductByDiscount(ViewState("min"), ViewState("max")).Rows.Clear()
        ElseIf ddlsort.SelectedItem.ToString = "Most Viewed" Then
            _bo.Topbrand(ViewState("min"), ViewState("max")).Rows.Clear()
        End If

        '_bo.extracthomeproduct(ViewState("min"), ViewState("max")).Rows.Clear()
        cntProduct = _bo.counttotproduct()
        'ViewState("min") = Val(ViewState("min")) + 8
        'ViewState("max") = Val(ViewState("max")) + 8

        If ddlsort.SelectedItem.ToString = "All" Then
            DataList.DataSource = _bo.extracthomeproduct(ViewState("min"), ViewState("max"))
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Price" Then

            dtTable = _bo.getProductByPrice(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Brand" Then

            dtTable = _bo.getProductByBrand(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Discount" Then
            dtTable = _bo.getProductByDiscount(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        ElseIf ddlsort.SelectedItem.ToString = "Most Viewed" Then
            dtTable = _bo.Topbrand(ViewState("min"), ViewState("max"))
            DataList.DataSource = dtTable
            DataList.DataBind()
        End If
        If ViewState("max") > cntProduct Then
            lnkNext.Enabled = False
        End If
        If ViewState("min") > 1 Then
            lnkPrevious.Enabled = True
        End If
    End Sub
End Class





